package com.rays.gank.ui.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

/**
 * Created by Rays on 2021/1/21.
 */
abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {

    abstract fun getLayoutResId(): Int

    abstract fun initView(savedInstanceState: Bundle?)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (getLayoutResId() != 0) {
            setContentView(getLayoutResId())
        }
        initView(savedInstanceState)
    }

    override fun onDestroy() {
        cancel()
        super.onDestroy()
    }
}